package b.i.l;

import android.content.res.Resources;
import android.os.SystemClock;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.ViewConfiguration;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.AnimationUtils;
import android.view.animation.Interpolator;
import b.i.k.o;
import com.huawei.agconnect.exception.AGCServerException;
import java.util.Objects;
import java.util.WeakHashMap;

/* compiled from: AutoScrollHelper */
public abstract class a implements OnTouchListener {
    public static final int q = ViewConfiguration.getTapTimeout();
    public final a a;
    public final Interpolator b = new AccelerateInterpolator();
    public final View c;
    public Runnable d;
    public float[] e = new float[]{0.0f, 0.0f};
    public float[] f = new float[]{Float.MAX_VALUE, Float.MAX_VALUE};
    public int g;
    public int h;
    public float[] i = new float[]{0.0f, 0.0f};
    public float[] j = new float[]{0.0f, 0.0f};
    public float[] k = new float[]{Float.MAX_VALUE, Float.MAX_VALUE};
    public boolean l;
    public boolean m;
    public boolean n;
    public boolean o;
    public boolean p;

    /* compiled from: AutoScrollHelper */
    public static class a {
        public int a;
        public int b;
        public float c;
        public float d;
        public long e = Long.MIN_VALUE;
        public long f = 0;
        public int g = 0;
        public int h = 0;
        public long i = -1;
        public float j;
        public int k;

        public final float a(long j) {
            long j2 = this.e;
            if (j < j2) {
                return 0.0f;
            }
            long j3 = this.i;
            if (j3 < 0 || j < j3) {
                return a.b(((float) (j - j2)) / ((float) this.a), 0.0f, 1.0f) * 0.5f;
            }
            j -= j3;
            float f = this.j;
            return (a.b(((float) j) / ((float) this.k), 0.0f, 1.0f) * f) + (1.0f - f);
        }
    }

    /* compiled from: AutoScrollHelper */
    public class b implements Runnable {
        public void run() {
            a aVar = a.this;
            if (aVar.o) {
                a aVar2;
                if (aVar.m) {
                    aVar.m = false;
                    aVar2 = aVar.a;
                    Objects.requireNonNull(aVar2);
                    long currentAnimationTimeMillis = AnimationUtils.currentAnimationTimeMillis();
                    aVar2.e = currentAnimationTimeMillis;
                    aVar2.i = -1;
                    aVar2.f = currentAnimationTimeMillis;
                    aVar2.j = 0.5f;
                    aVar2.g = 0;
                    aVar2.h = 0;
                }
                aVar2 = a.this.a;
                Object obj = (aVar2.i <= 0 || AnimationUtils.currentAnimationTimeMillis() <= aVar2.i + ((long) aVar2.k)) ? null : 1;
                if (obj == null && a.this.e()) {
                    a aVar3 = a.this;
                    if (aVar3.n) {
                        aVar3.n = false;
                        Objects.requireNonNull(aVar3);
                        long uptimeMillis = SystemClock.uptimeMillis();
                        MotionEvent obtain = MotionEvent.obtain(uptimeMillis, uptimeMillis, 3, 0.0f, 0.0f, 0);
                        aVar3.c.onTouchEvent(obtain);
                        obtain.recycle();
                    }
                    if (aVar2.f != 0) {
                        long currentAnimationTimeMillis2 = AnimationUtils.currentAnimationTimeMillis();
                        float a = aVar2.a(currentAnimationTimeMillis2);
                        a = (a * 4.0f) + ((-4.0f * a) * a);
                        long j = currentAnimationTimeMillis2 - aVar2.f;
                        aVar2.f = currentAnimationTimeMillis2;
                        float f = ((float) j) * a;
                        aVar2.g = (int) (aVar2.c * f);
                        int i = (int) (f * aVar2.d);
                        aVar2.h = i;
                        ((c) a.this).r.scrollListBy(i);
                        View view = a.this.c;
                        WeakHashMap weakHashMap = o.a;
                        view.postOnAnimation(this);
                        return;
                    }
                    throw new RuntimeException("Cannot compute scroll delta before calling start()");
                }
                a.this.o = false;
            }
        }
    }

    public a(View view) {
        a aVar = new a();
        this.a = aVar;
        this.c = view;
        float f = Resources.getSystem().getDisplayMetrics().density;
        int i = (int) ((f * 315.0f) + 0.5f);
        float f2 = (float) ((int) ((1575.0f * f) + 0.5f));
        float[] fArr = this.k;
        f2 /= 1000.0f;
        fArr[0] = f2;
        fArr[1] = f2;
        f = (float) i;
        float[] fArr2 = this.j;
        f /= 1000.0f;
        fArr2[0] = f;
        fArr2[1] = f;
        this.g = 1;
        float[] fArr3 = this.f;
        fArr3[0] = Float.MAX_VALUE;
        fArr3[1] = Float.MAX_VALUE;
        fArr3 = this.e;
        fArr3[0] = 0.2f;
        fArr3[1] = 0.2f;
        fArr3 = this.i;
        fArr3[0] = 0.001f;
        fArr3[1] = 0.001f;
        this.h = q;
        aVar.a = AGCServerException.UNKNOW_EXCEPTION;
        aVar.b = AGCServerException.UNKNOW_EXCEPTION;
    }

    public static float b(float f, float f2, float f3) {
        return f > f3 ? f3 : f < f2 ? f2 : f;
    }

    /* JADX WARNING: Removed duplicated region for block: B:11:0x003f  */
    /* JADX WARNING: Removed duplicated region for block: B:10:0x003e A:{RETURN} */
    public final float a(int r4, float r5, float r6, float r7) {
        /*
        r3 = this;
        r0 = r3.e;
        r0 = r0[r4];
        r1 = r3.f;
        r1 = r1[r4];
        r0 = r0 * r6;
        r2 = 0;
        r0 = b(r0, r2, r1);
        r1 = r3.c(r5, r0);
        r6 = r6 - r5;
        r5 = r3.c(r6, r0);
        r5 = r5 - r1;
        r6 = (r5 > r2 ? 1 : (r5 == r2 ? 0 : -1));
        if (r6 >= 0) goto L_0x0026;
    L_0x001d:
        r6 = r3.b;
        r5 = -r5;
        r5 = r6.getInterpolation(r5);
        r5 = -r5;
        goto L_0x0030;
    L_0x0026:
        r6 = (r5 > r2 ? 1 : (r5 == r2 ? 0 : -1));
        if (r6 <= 0) goto L_0x0039;
    L_0x002a:
        r6 = r3.b;
        r5 = r6.getInterpolation(r5);
    L_0x0030:
        r6 = -1082130432; // 0xffffffffbf800000 float:-1.0 double:NaN;
        r0 = 1065353216; // 0x3f800000 float:1.0 double:5.263544247E-315;
        r5 = b(r5, r6, r0);
        goto L_0x003a;
    L_0x0039:
        r5 = 0;
    L_0x003a:
        r6 = (r5 > r2 ? 1 : (r5 == r2 ? 0 : -1));
        if (r6 != 0) goto L_0x003f;
    L_0x003e:
        return r2;
    L_0x003f:
        r0 = r3.i;
        r0 = r0[r4];
        r1 = r3.j;
        r1 = r1[r4];
        r2 = r3.k;
        r4 = r2[r4];
        r0 = r0 * r7;
        if (r6 <= 0) goto L_0x0056;
    L_0x004f:
        r5 = r5 * r0;
        r4 = b(r5, r1, r4);
        return r4;
    L_0x0056:
        r5 = -r5;
        r5 = r5 * r0;
        r4 = b(r5, r1, r4);
        r4 = -r4;
        return r4;
        */
        throw new UnsupportedOperationException("Method not decompiled: b.i.l.a.a(int, float, float, float):float");
    }

    public final float c(float f, float f2) {
        if (f2 == 0.0f) {
            return 0.0f;
        }
        int i = this.g;
        if (i == 0 || i == 1) {
            if (f < f2) {
                if (f >= 0.0f) {
                    return 1.0f - (f / f2);
                }
                return (this.o && i == 1) ? 1.0f : 0.0f;
            }
        } else if (i == 2 && f < 0.0f) {
            return f / (-f2);
        }
    }

    public final void d() {
        int i = 0;
        if (this.m) {
            this.o = false;
            return;
        }
        a aVar = this.a;
        Objects.requireNonNull(aVar);
        long currentAnimationTimeMillis = AnimationUtils.currentAnimationTimeMillis();
        int i2 = (int) (currentAnimationTimeMillis - aVar.e);
        int i3 = aVar.b;
        if (i2 > i3) {
            i = i3;
        } else if (i2 >= 0) {
            i = i2;
        }
        aVar.k = i;
        aVar.j = aVar.a(currentAnimationTimeMillis);
        aVar.i = currentAnimationTimeMillis;
    }

    /* JADX WARNING: Removed duplicated region for block: B:18:? A:{SYNTHETIC, RETURN} */
    public boolean e() {
        /*
        r9 = this;
        r0 = r9.a;
        r1 = r0.d;
        r2 = java.lang.Math.abs(r1);
        r1 = r1 / r2;
        r1 = (int) r1;
        r0 = r0.c;
        r2 = java.lang.Math.abs(r0);
        r0 = r0 / r2;
        r0 = (int) r0;
        r2 = 1;
        r3 = 0;
        if (r1 == 0) goto L_0x0053;
    L_0x0016:
        r4 = r9;
        r4 = (b.i.l.c) r4;
        r4 = r4.r;
        r5 = r4.getCount();
        if (r5 != 0) goto L_0x0023;
    L_0x0021:
        r1 = 0;
        goto L_0x0051;
    L_0x0023:
        r6 = r4.getChildCount();
        r7 = r4.getFirstVisiblePosition();
        r8 = r7 + r6;
        if (r1 <= 0) goto L_0x0041;
    L_0x002f:
        if (r8 < r5) goto L_0x0050;
    L_0x0031:
        r6 = r6 - r2;
        r1 = r4.getChildAt(r6);
        r1 = r1.getBottom();
        r4 = r4.getHeight();
        if (r1 > r4) goto L_0x0050;
    L_0x0040:
        goto L_0x0021;
    L_0x0041:
        if (r1 >= 0) goto L_0x0021;
    L_0x0043:
        if (r7 > 0) goto L_0x0050;
    L_0x0045:
        r1 = r4.getChildAt(r3);
        r1 = r1.getTop();
        if (r1 < 0) goto L_0x0050;
    L_0x004f:
        goto L_0x0021;
    L_0x0050:
        r1 = 1;
    L_0x0051:
        if (r1 != 0) goto L_0x0054;
    L_0x0053:
        r2 = 0;
    L_0x0054:
        return r2;
        */
        throw new UnsupportedOperationException("Method not decompiled: b.i.l.a.e():boolean");
    }

    /* JADX WARNING: Missing block: B:9:0x0013, code skipped:
            if (r0 != 3) goto L_0x007f;
     */
    public boolean onTouch(android.view.View r6, android.view.MotionEvent r7) {
        /*
        r5 = this;
        r0 = r5.p;
        r1 = 0;
        if (r0 != 0) goto L_0x0006;
    L_0x0005:
        return r1;
    L_0x0006:
        r0 = r7.getActionMasked();
        r2 = 1;
        if (r0 == 0) goto L_0x001a;
    L_0x000d:
        if (r0 == r2) goto L_0x0016;
    L_0x000f:
        r3 = 2;
        if (r0 == r3) goto L_0x001e;
    L_0x0012:
        r6 = 3;
        if (r0 == r6) goto L_0x0016;
    L_0x0015:
        goto L_0x007f;
    L_0x0016:
        r5.d();
        goto L_0x007f;
    L_0x001a:
        r5.n = r2;
        r5.l = r1;
    L_0x001e:
        r0 = r7.getX();
        r3 = r6.getWidth();
        r3 = (float) r3;
        r4 = r5.c;
        r4 = r4.getWidth();
        r4 = (float) r4;
        r0 = r5.a(r1, r0, r3, r4);
        r7 = r7.getY();
        r6 = r6.getHeight();
        r6 = (float) r6;
        r3 = r5.c;
        r3 = r3.getHeight();
        r3 = (float) r3;
        r6 = r5.a(r2, r7, r6, r3);
        r7 = r5.a;
        r7.c = r0;
        r7.d = r6;
        r6 = r5.o;
        if (r6 != 0) goto L_0x007f;
    L_0x0050:
        r6 = r5.e();
        if (r6 == 0) goto L_0x007f;
    L_0x0056:
        r6 = r5.d;
        if (r6 != 0) goto L_0x0061;
    L_0x005a:
        r6 = new b.i.l.a$b;
        r6.m549init();
        r5.d = r6;
    L_0x0061:
        r5.o = r2;
        r5.m = r2;
        r6 = r5.l;
        if (r6 != 0) goto L_0x0078;
    L_0x0069:
        r6 = r5.h;
        if (r6 <= 0) goto L_0x0078;
    L_0x006d:
        r7 = r5.c;
        r0 = r5.d;
        r3 = (long) r6;
        r6 = b.i.k.o.a;
        r7.postOnAnimationDelayed(r0, r3);
        goto L_0x007d;
    L_0x0078:
        r6 = r5.d;
        r6.run();
    L_0x007d:
        r5.l = r2;
    L_0x007f:
        return r1;
        */
        throw new UnsupportedOperationException("Method not decompiled: b.i.l.a.onTouch(android.view.View, android.view.MotionEvent):boolean");
    }
}
